package com.yidu.BusinessParament.service.impl;

import com.yidu.BusinessParament.entity.DealSeat;
import com.yidu.BusinessParament.mapper.DealSeatMapper;
import com.yidu.BusinessParament.service.DealSeatService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @交易席位 Impl类
 * @version 1.0
 * @auther 林肯
 * @date 2022/12/12 -9:37
 */
@Service
public class DealSeatServiceImpl implements DealSeatService {
    @Resource
    private DealSeatMapper dealSeatMapper;

    /**
     * 查询+分页
     * @param page 页码
     * @param limit 每页显示的条数
     * @param dealSeat 交易席位
     * @return
     */
    @Override
    public List<DealSeat> selectDealSeat(int page, int limit, DealSeat dealSeat) {
        //创建Map对象
        Map map = new HashMap();
        //把值放入在Map集合里
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        //把按条件查询方法放入Map集合中
        map.put("sqlWhere",buildStrWhere(dealSeat));
        //返回值
        return dealSeatMapper.selectDealSeat(map);
    }

    /**
     * 生成条件字符串
     * @param dealSeat 生成条件的参数
     * @return 条件字符串  and fundId like '%%'
     */
    public String buildStrWhere(DealSeat dealSeat){
        StringBuffer strWhere = new StringBuffer("");
        if(dealSeat.getSeatId ()!=null && !dealSeat.getSeatId ().equals(""))
        {
            strWhere.append(" and d.seatId like  '%"+dealSeat.getSeatId ()+"%'");
        }
        if (dealSeat.getSeatType()!=0){
            strWhere.append(" and d.seatType = '"+dealSeat.getSeatType()+"'");
        }
        if (dealSeat.getBrokerId()!=null && !dealSeat.getBrokerId().equals("")){
            strWhere.append(" and d.brokerId = '"+dealSeat.getBrokerId()+"'");
        }
        return  strWhere.toString();
    }

    /**
     * 查行数 + 名字查（按名字模糊查）
     * @param dealSeat 交易席位
     * @return
     */
    @Override
    public int selectCount(DealSeat dealSeat) {
        Map map=new HashMap();
        map.put("sqlWhere",buildStrWhere(dealSeat));
        int count = dealSeatMapper.selectCount(map);
        return count;
    }

    /**
     * 添加数据
     * @param dealSeat 交易席位
     * @return
     */
    @Override
    public int insertDealSeat(DealSeat dealSeat) {
         return dealSeatMapper.insertDealSeat(dealSeat);
    }

    /**
     * 删除数据
     * @param seatId 席位编号
     * @return
     */
    @Override
    public int deleteDealSeat(String seatId) {
        //将id转为数据
        String[] split = seatId.split(",");
        //创建存放id的集合
        ArrayList<String> equityDataIdList = new ArrayList<String>();
        for (String id : split) {
            //将转换的id放入集合中
            equityDataIdList.add(id);
        }
        return dealSeatMapper.deleteDealSeat(equityDataIdList);
    }

    /**
     * 修改数据
     * @param dealSeat 交易席位
     * @return
     */
    @Override
    public int updateDealSeat(DealSeat dealSeat) {
        return dealSeatMapper.updateDealSeat(dealSeat);
    }

    /**
     * 获取最大ID
     * @return
     */
    @Override
    public String selectMaxId() {
        return dealSeatMapper.selectMaxId();
    }
}
